var express = require('express');
var query = require('./db');
var addressRouter = express.Router();

addressRouter.post('/addAddress', function (req, res, next) {
    let sql=`insert into address(uid,name,tel,addressinfo) values(${req.cookies.uid},'${req.body.name}','${req.body.tel}','${req.body.address}')`;
    query(sql, function (err, result) {
        let obj={
            status:200,
            data:result
        }
        if(err){
            status=0;
            data=err;
            res.send(obj);
        }
        else{
            res.send(obj);
        }
    });
});

addressRouter.get('/getAddressList',function(req,res,next){
    let sql=`select * from address where uid = ${req.cookies.uid}`;
    query(sql, function (err, result) {
        let obj={
            status:200,
            data:result
        }
        if(err){
            status=0;
            data=err;
            res.send(obj);
        }
        else{
            res.send(obj);
        }
    });
})


addressRouter.post('/delAddress',function(req,res,next){
    let sql=`delete  from address where aid = ${req.body.aid}`;
   
    query(sql, function (err, result) {
        let obj={
            status:200,
            data:result
        }
        if(err){
            status=0;
            data=err;
            res.send(obj);
        }
        else{
            res.send(obj);
        }
    });
})
module.exports = addressRouter;